package com.dmz.test.demos.web;//package com.dmz.api.test;

import cn.hutool.extra.ftp.SimpleFtpServer;
import org.apache.ftpserver.ftplet.Authority;
import org.apache.ftpserver.usermanager.impl.BaseUser;
import org.apache.ftpserver.usermanager.impl.WritePermission;

import java.util.Collections;

/**
 *
 * @author：lee <p>
 * DateTime：2024-10-31 14:47
 */
//@Component
public class FtpServer {

    //@PostConstruct
    public void socketStart(){
        //直接另起一个线程挂起ftp服务
        new Thread(this::ftpServer).start();
    }

    private void ftpServer() {
        String path = "E:\\\\work\\\\src\\\\test\\\\remote\\\\";
        BaseUser user = new BaseUser();
        user.setName("root");
        user.setPassword("root");
        //user.setHomeDirectory("E:\\work\\src\\test\\remote\\");
        user.setHomeDirectory(path);
        Authority writePermission = new WritePermission();
        user.setAuthorities(Collections.singletonList(writePermission));
        SimpleFtpServer
                .create().setPort(21221)
                .addUser(user)
                .start();
    }
}
